package svcregistry

import (
	"starsine.cn/appTpl/cmn/config/aconf"
	. "starsine.cn/appTpl/cmn/defs"
	"starsine.cn/appTpl/cmn/logs"
	grpcclient "starsine.cn/appTpl/svcregistry/grpc/client"
	grpchandler "starsine.cn/appTpl/svcregistry/grpc/handler"
	wshandler "starsine.cn/appTpl/svcregistry/restful/handler"
	"starsine.cn/appTpl/svcregistry/restful/token"
	"starsine.cn/appTpl/svcregistry/restful/ws-client"
)

var mode = "grpc"

func Start(appCtxt *AppContext) {
	mode = aconf.GetString("SvcCenter.RegistryMode", "grpc", aconf.WithENV("sc_mode"))

	if mode == "ws" {
		token.Start(appCtxt)
		ws.Start(appCtxt)
		wshandler.Start(appCtxt)
	} else {
		grpcclient.Start(appCtxt)
		grpchandler.Start(appCtxt)
	}

	logs.Infof("registry(rpcMode: %s) start", mode)
}

func GetInstanceID() string {
	if mode == "ws" {
		return wshandler.GetInstanceID()
	} else {
		return grpchandler.GetInstanceID()
	}
}
